<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /* 
      先请求A   在请求B   在请求C
    */

    function getName() {
      return new Promise((resolve, reject) => {
        try {
          console.log("请求A的数据.......");
          // throw new Error("A错误")
          setTimeout(() => {
            console.log("A请求成功");
            const obj1 = {
              name: "liuMin"
            }
            resolve(obj1)
          }, 1500)
        } catch (e) {
          reject(e.message)
        }
      })
    }

    function getAge(name) {
      return new Promise((resolve, reject) => {
        try {
          console.log("请求B的数据.......");
          // throw new Error("B错误")
          setTimeout(() => {
            console.log("B请求成功");
            const age = {
              age: 31
            }
            resolve({
              ...name,
              ...age
            })
          }, 1500)
        } catch (e) {
          reject(e.message)
        }
      })
    }

    function getGender(age) {
      return new Promise((resolve, reject) => {
        try {
          console.log("请求C的数据.......");
          // throw new Error("C错误")
          setTimeout(() => {
            console.log("C请求成功");
            const gender = {
              gender: "男"
            }
            resolve({
              ...age,
              ...gender
            })
          }, 1500)
        } catch (e) {
          reject(e.message)
        }
      })
    }

    async function getData() {
      const name = await getName() //调用getName函数获取name属性·
      const age = await getAge(name) //将getName函数的值传递给getAge
      const gender = await getGender(age)


      console.log("完整数据是", gender);
    }
    getData()
  </script>
</body>

</html>